package com.nuanshui.heatedloan.web;

import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonFormat;

@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum GlobalErrorCode {
	// 
	SUCESS(200, "Success"),
	FAIL(300,""),
	//
	UNAUTHORIZED(401, "Unauthorized"),
	//
	NOT_FOUND(404, "Resource not found"),
	//
	INTERNAL_ERROR(500, "Server internal error"),
	//用户提交的参数有误
	INVALID_ARGUMENT(11001, "Invalid argument"),
	//
	UNKNOWN(-1, "Unknown error"),
	//数组库中 的数据不存在
	DATA_NOT_EXIST(301,"data not exist"),
	
	INTERFACE_SHUTDOWN(302,"interface shutdown"),
	
	SIGN_ILLEGAL(303,"sign_illegal"),
	
	FORBIDDEN(403,"Forbidden");

	private static final Map<Integer, GlobalErrorCode> values = new HashMap<Integer, GlobalErrorCode>();
	static {
		for (GlobalErrorCode ec : GlobalErrorCode.values()) {
			values.put(ec.errorCode, ec);
		}
	}

	private int errorCode;
	private String error;

	private GlobalErrorCode(int errorCode, String error) {
		this.errorCode = errorCode;
		this.error = error;
	}

	public static GlobalErrorCode valueOf(int code) {
		GlobalErrorCode ec = values.get(code);
		if (ec != null)
			return ec;
		return UNKNOWN;
	}

	public int getErrorCode() {
		return errorCode;
	}

	public String getError() {
		return error;
	}
}
